package org.dizem.freepl0.compiler.errormanager;


import org.dizem.freepl0.compiler.*;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: DIZEM
 * Date: 11-2-1
 * Time: 下午9:38
 */
public class ErrorManager {

	private List<ErrorInfo> errorInfoList = new ArrayList<ErrorInfo>();
	private WordAnalysis wordAnalysis;
	private FPCompiler compiler;
	public ErrorManager(FPCompiler compiler) {
		this.compiler = compiler;
	}

	public void addError(int id) {
		System.out.println("Add error id = " + id);
		errorInfoList.add(new ErrorInfo(id, getError(id), compiler.getWordAnalysis().getLine()));
	}

	public List<ErrorInfo> getErrorInfoList() {
		return errorInfoList;
	}

	public String getError(int id) {
		switch (id) {
			case 1:
				return "常数说明中的\"=\"写成\":=\"!";
			case 2:
				return "常数说明中的\"=\"后应是数字!";
			case 3:
				return "常数说明中标识符后应是\"=\"!";
			case 4:
				return "const, var, procedure 后应是标识符!";
			case 5:
				return "漏掉了\',\' 或\';\'!";
			case 6:
				return "过程说明后的符号不正确(应是语句开始符,或过程定义符!";
			case 7:
				return "应是语句开始符!";
			case 8:
				return "程序体内的语句部分的后跟符不正确!";
			case 9:
				return "程序结尾丢了句号\'.\'!";
			case 10:
				return "语句之间漏了\';\'!";
			case 11:
				return "标识符未说明!";
			case 12:
				return "赋值语句中, 赋值号左部标识符属性应是变量!";
			case 13:
				return "赋值语句左部标识符后应是赋值号\':=\'!";
			case 14:
				return "call 后应为标识符!";
			case 15:
				return "call 后标识符属性应为过程!";
			case 16:
				return "条件语句中丢了\'then\'!";
			case 17:
				return "丢了\'end\' 或\';\'!";
			case 18:
				return "while 型循环语句中丢了\'do\'!";
			case 19:
				return "语句后的符号不正确!";
			case 20:
				return "应为关系运算符!";
			case 21:
				return "表达式内标识符属性不能是过程!";
			case 22:
				return "表达式中漏掉右括号\'(\'!";
			case 23:
				return "因子后的非法符号!";
			case 24:
				return "表达式的开始符不能是此符号!";
			case 25:
				return "repeat 型循环语句中没有until!";
			case 26:
				return "标识符太长!";
			case 27:
				return "程序过长!";
			case 28:
				return "write后缺少左括号\"(\"";
			case 30:
				return "数位太长!";
			case 31:
				return "数越界!";
			case 32:
				return "嵌套层数太多!";
			case 33:
				return "read语句括号中的标识符不是变量!";
		}

		return "";
	}
}
